<!DOCTYPE html>
<html lang="en">
<head>
    <link href="/resources/css/table.css?r=3" rel="stylesheet">
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script src="/resources/js/fk.js"></script>
    <style type="text/css">
        td{
            min-height:50px;
        }
    </style>
</head>
<body>
<table>
    <tr>
        <td class="name" height="45px">名称 </td>
        <td class="form-data value" name="name"></td>

        <td class="name" rowspan="4" >图示</td>
        <td rowspan="4" class="value">
            <div id="imgDiv" >
                <img  style="cursor: pointer; width:180px;height:180px;" />
            </div>
        </td>
    </tr>
    <tr>
        <td class="name" height="45px">产品属性</td>
        <td class="form-data value"  name="productAttr"></td>

    </tr>
    <tr>
        <td class="name" height="45px">危化品分类</td>
        <td class="form-data value" name="mProductClass"></td>
    </tr>
    <tr>

        <td class="name" height="45px">单位</td>
        <td class="form-data value" name="unit"></td>

    </tr>
    <tr>
        <td class="name" colspan="4" style="text-align: left">&nbsp&nbsp&nbsp&nbsp产品简介</td>

    </tr>
    <tr>
        <td name="desc" class="form-data value" name="desc" colspan="4"  valign="top"
            style="height:350px;white-space:normal !important;text-align: left"  ></td>
    </tr>
</table>

</body>
<script type="text/javascript">
    $(function () {
        setTitle("基本信息>产品");
        initData();
    });

    function initData(){
        var data = getData();
        var id = data.id;
        if(null2empty(id) !==""){
            $("input[name='id']").val(id);
            $.ajax({
                url:"/admin/mProduct/find.do",
                data:{'id':id},
                type:'post',
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        initPageDate(data.data, '.form-data');
                        $("#imgDiv img").attr("src",data.data.icon);
                        /*if(!isNullOrUndefined(data.data.icon)){
                         var imgArray =  new Array();
                         imgArray.push({"id":data.data.icon,"path":data.data.icon});
                         addFileInfoToTable(imgArray);
                         }*/
                    }
                }
            });
            $("#account").attr('readonly','readonly');
        }

    }

    function save() {
        var params = getPageDataByClass("form-data");
        if (strIsNull(params['name'])) {
            alert("请输入危险品名称");
            return;
        }
        if (strIsNull(params['status'])) {
            alert("请选择状态");
            return;
        }
        var img = $("#imgDiv img");
        if(img.length > 0) {
            params['icon'] = $(img[0]).attr("src");
        }else{
            alert("请上传首图");
            return;
        }
        $.ajax({
            url: "/admin/mProduct/save.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    goto("m_product_list.html");
                } else {
                    alert(data.msg);
                }
            }
        });
    }
    function back() {
        goto("m_product_list.html");
    }
</script>
</html>